/**
 * Bestpay.com.cn Inc.
 * Copyright (c) 2011-2020 All Rights Reserved.
 */
package com.suxiaoxiao.springbootlearn.designpattern.statepattern.goodcode.stateimpl;

import com.suxiaoxiao.springbootlearn.designpattern.statepattern.goodcode.State;
import com.suxiaoxiao.springbootlearn.designpattern.statepattern.goodcode.pojo.GumballMachine;

/**
 * desc
 *
 * @author zhaorongzhang
 * @version WinnerState.java, v 0.1 2020/1/11 4:05 下午 zhaorongzhang Exp $$
 */
public class WinnerState extends State {

    transient GumballMachine gumballMachine;

    public WinnerState(GumballMachine gumballMachine) {
        this.gumballMachine = gumballMachine;
    }

    @Override
    public void dispense() {
        System.out.println("恭喜您，获得双倍奖励。");
        gumballMachine.releaseBall();
        if (gumballMachine.getCount() == 0) {
            gumballMachine.setState(gumballMachine.getSoldOutState());
        } else {
            gumballMachine.releaseBall();
            if (gumballMachine.getCount() > 0) {
                gumballMachine.setState(gumballMachine.getNoQuarterState());
            } else {
                System.out.println("卖光啦");
                gumballMachine.setState(gumballMachine.getSoldOutState());
            }
        }
    }

}